const fs = require("fs")
const path = require("path")
// 创建文件夹
const dirname = "./zyw"
if (!fs.existsSync(dirname)) {
  fs.mkdir(dirname, err => {
    console.log(err);
  })
}


//读取文件夹的所有文件
fs.readdir(dirname, (err, files) => {
  console.log(files);
})


function getFiles(dirname) {
  fs.readdir(dirname, {
    withFileTypes: true
  }, (err, files) => {
    files.forEach(e => {
      if (e.isDirectory()) {
        const filepath = path.resolve(dirname, e.name)
        getFiles(filepath)
      } else {
        console.log(e.name);
      }
    })
  })
}
getFiles(dirname)
//3.文件夹的重命名


fs.rename("./zyw/test.js", "./zyw/newtest.js", err => {
  console.log(err);
})